﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>机构系统参数</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/lobsteruiframe/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/lobsteruiframe/layuiadmin/style/admin.css" rel="stylesheet" />
    <script src="/lobsteruiframe/layuiadmin/layui/layui.js"></script>
    <script src="/jslib/jquery-3.4.1.min.js"></script>
    <script src="/jslib/lobster.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header layui-form layuiadmin-card-header-auto">
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">机构：</label>
                        <div class="layui-input-block">
                            <select name="workId" id="workId" lay-filter="workId"></select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用：</label>
                        <div class="layui-input-block">
                            <select name="appId" id="appId" lay-filter="appId"></select>
                        </div>
                    </div>
                </div>
                
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">业务系统：</label>
                        <div class="layui-input-block">
                            <select name="typeSelect" id="LAY-parameter-get-type" lay-filter="LAY-parameter-get-type"></select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">查询条件：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="searchkey" type="text" name="searchkey" placeholder="请输入参数标识/参数名称" />
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-parameter-get-config" id="btnSearch">
                            <i class="layui-icon layuiadmin-button-btn layui-icon-search"></i>查询
                        </button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="LAY-system-parameter" lay-filter="LAY-system-parameter"></table>
               
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    lobsterlayui.main(['index', 'layer', 'form', 'element', 'table'], {
        data: {
            $layui: null,
            right: null,
            tablepara:null,
        },
        pageload: function (right) {
            this.data.right = right;
            this.loadselecttype();
            this.loadselectworker(() => {
                this.loadselectapp(() => {
                    this.data.tablepara=this.loadtablepara();
                })
            })
            this.initevent();
        },
        initevent() {
            var self = this;
            //查找
            layui.form.on('submit(LAY-parameter-get-config)', function (data) {
                console.log(data);
                self.data.tablepara.reload({
                    where: {
                        workid: $("#workId").val(),
                        appid: $("#appId").val(),
                        systype: $("#LAY-parameter-get-type").val(),
                        searchkey: $("#searchkey").val()
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });

            //监听行工具栏事件（编辑、启停用）
            layui.table.on('tool(LAY-system-parameter)', function (obj) {  //LAY-system-parameter是lay-filter值
                var data = obj.data;//当前行数据
                console.log(data);
                var tr = obj.tr;
                var layEvent = obj.event;//获得lay-event的值
                switch (obj.event) {
                    case 'edit':
                        layer.open({
                            type: 1
                            , title: '编辑系统参数'
                            , content: $('#dlg_parameterform').html()
                            , area: ['680px', '440px']  //宽，高
                            , btn: ['保存', '取消']
                            , resize: false
                            , success: function (layero, index) {
                                setTimeout(function () {
                                    //执行完毕，layer的动画一般是执行300毫秒
                                    var othis = $("#layuiadmin-form-parameter");
                                    othis.find('input[name="ID"]').val(data.ID);
                                    othis.find('input[name="ParaName"]').val(data.ParaName);
                                    othis.find('input[name="ParaID"]').val(data.ParaID);
                                    othis.find('textarea[name="Value"]').text(data.Value);
                                    othis.find('input[name="WorkId"]').val(data.WorkId);
                                    othis.find('input[name="AppID"]').val(data.AppID);

                                    //layui.form.render("select");
                                }, 300);
                            }
                            , btn2: function (index, layero) {
                                tr.removeAttr("class");
                            }
                            , cancel: function () {
                                tr.removeAttr("class");
                            }
                            , yes: function (index, layero) {
                                var submit = $('#LAY-parameter-form-submit');

                                //监听提交
                                layui.form.on('submit(LAY-parameter-form-submit)', function (data) {
                                    self.saveparameter(data, index);
                                });
                                submit.trigger('click');
                            }
                        });
                        break;
                    case 'setup':
                        layer.confirm("确定要启用吗?", { icon: 3, title: "提示" },
                            function (index) {
                                layer.close(index); //关闭弹层

                                var para={
                                    Id:0,
                                    WorkId: $("#workId").val(),
                                    AppID: data.AppID,
                                    ParaID: data.ParaID,
                                    ParaName: data.ParaName,
                                    Value: data.Value
                                }
                                lobsterlayui.POST('/admin/v1/workerparameter/SetupParameter',para).then(retdata=>{
                                    layer.msg("启用成功");
                                    self.data.tablepara.reload();
                                })

                            });
                        break;
                };

            });
        },
        loadselectworker(callback){
            //获取机构数据
            lobsterlayui.GET('/admin/v1/worker/GetSelectWorkerDataByUser').then(data => {
                //医疗机构
                var workers = data["Workers"];
                $("#workId").html("");
                $.each(workers, function (i, item) {
                    $("#workId").append("<option value=\"" + item.WorkId + "\">" + item.WorkName + "</option>");
                });

                $('#workId').val(workers[0].WorkId);//默认选择当前登录机构
                //重新渲染
                layui.form.render("select");

                if (callback) {
                    callback();
                }
            });

            //监听机构下拉框
            layui.form.on('select(workId)', function () {
                if (callback) {
                    callback();
                }
            });
        },
        //加载应用
        loadselectapp : function (callback) {

            lobsterlayui.GET('/admin/v1/worker/GetSimpleAppData',{workid:$('#workId').val()}).then(retdata=>{
                 //应用列表
                 var appdata = retdata["appdata"];
                    $("#appId").html("");
                    $.each(appdata, function (i, item) {
                        $("#appId").append("<option value=\"" + item.AppId + "\">" + item.AppName + "</option>");
                    });
                    //重新渲染
                    layui.form.render("select");

                    if (callback) {
                        callback();
                    }
            })

            //监听应用下拉框
            layui.form.on('select(appId)', function () {
                if (callback) {
                    callback();
                }
            });
        },
        //获取业务类型数据
        loadselecttype : function (callback) {

            lobsterlayui.GET('/admin/v1/workerparameter/GetSystemType').then(retdata=>{
                //业务系统
                var type = retdata["data"]; 
                $("#LAY-parameter-get-type").html("");
                $("#LAY-parameter-get-type").append("<option value=-1>全部</option>");
                $.each(type, function (i, item) {
                    $("#LAY-parameter-get-type").append("<option value=\"" + item.ID + "\">" + item.Name + "</option>");
                });
                //重新渲染
                layui.form.render("select");

                if (callback) {
                    callback();
                }
            })
        },
        loadtablepara : function () {
            //表格渲染
            return layui.table.render({
                elem: '#LAY-system-parameter'
                ,headers:lobsterlayui.GetHeaderData()
                , where: {
                    workid: $("#workId").val() || 0,
                    appid: $("#appId").val() || 0,
                    systype: $("#LAY-parameter-get-type").val() || -1,
                    searchkey: $("#searchkey").val()
                }
                , height: 'full-130'
                , cellMinWidth: 80 //全局定义常规单元格的最小宽度
                , url: '/admin/v1/workerparameter/GetSystemConfigData' //数据接口
                , page: true //开启分页
                , cols: [[ //表头
                    { field: 'ID', title: 'ID', width: '80' } 
                    , { field: 'ParaName', title: '参数名称', width: '150' }
                    , { field: 'ParaID', title: '参数标识', width: '150' }
                    , { field: 'Value', title: '参数结果', width: '300' }
                    , { field: 'Memo', title: '说明', width: '300' }
                    , { field: 'TypeName', title: '业务系统', width: '100' }
                    , { field: 'StopState', title: '标识状态', width: '100', align: 'center', templet: '#flagTpl' }
                    , { title: '操作', width: '100', align: 'center', fixed: 'right', toolbar: '#bar' }
                ]],
                parseData: function (res) {
                    return {
                        code: res.code,
                        msg: res.msg,
                        count: res.data.count,
                        data: res.data.data
                    }
                }
            });
        },
        saveparameter(data){
            var self=this;
            var field = data.field; //获取提交的字段
            var load = layer.msg('正在处理，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });

            lobsterlayui.POST('/admin/v1/workerparameter/SaveSystemConfig',field).then(retdata=>{
                layer.msg("保存成功");
                layer.closeAll();
                self.data.tablepara.reload();
            })
        }
    })
</script>

<script type="text/html" id="flagTpl">
    {{#  if(d.StopState == '1'){ }}
    <span style="color:red;">已停用</span>
    {{#  } else if(d.StopState == '-1') { }}
    <span style="color: red;">未启用</span>
    {{#  } }}
</script>
<script type="text/html" id="bar">

    {{#  if(d.StopState == '0'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    {{#  } else if(d.StopState == '-1') { }}
    <a class="layui-btn layui-btn-xs" lay-event="setup"><i class="layui-icon layui-icon-edit"></i>启用</a>
    {{#  } }}

</script>

<script type="text/html" id="dlg_parameterform">
    <form class="layui-form" lay-filter="layuiadmin-form-parameter" id="layuiadmin-form-parameter" style="padding: 20px 30px 0 0;">
   
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>参数名称</label>
            <div class="layui-input-block">
                <input type="text" name="ParaName" id="ParaName" lay-verify="required" placeholder="请输入参数名称" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>参数标识</label>
            <div class="layui-input-block">
                <input type="text" name="ParaID" id="ParaID" lay-verify="required" placeholder="请输入参数标识" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>参数结果</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" name="Value" lay-verify="required" placeholder="请输入参数结果"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="text" name="ID" id="ID" value="0">
            <input type="text" name="WorkId" id="WorkId" value="0">
            <input type="text" name="AppID" id="AppID" value="0">
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-parameter-form-submit" id="LAY-parameter-form-submit" value="确认">
        </div>
    </form>
</script>